<?php

namespace App\Http\Controllers\Admin;

use App\Http\Classes\Help;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class HelpController extends Controller
{

    public function viewAboutUs()
    {
        try
        {
            $help = new Help();

            $help = $help->getAboutUs();

            return view('admins.aboutUs')->with('help', $help);
        }
        catch (\Exception $exception)
        {
            return $this->exceptionView($exception, __FUNCTION__);
        }
    }

    public function viewCustomerService()
    {
        try
        {
            $help = new Help();

            $help = $help->getCustomerService();

            return view('admins.customerService')->with('help', $help);
        }
        catch (\Exception $exception)
        {
            return $this->exceptionView($exception, __FUNCTION__);
        }
    }

    public function viewHelp()
    {
        try
        {
            $help = new Help();

            $help = $help->getHelp();

            return view('admins.help')->with('help', $help);
        }
        catch (\Exception $exception)
        {
            return $this->exceptionView($exception, __FUNCTION__);
        }
    }

    public function updateAboutUs(Request $request)
    {
        try
        {
            if ( ! $request->has('content') || ! isEmptyString($request->get('content')) )
            {
                return view('errors.500')->with('message', '参数错误');
            }

            $content = $request->get('content');
            $help = new Help();
            $flag = $help->updateAboutUs($content);

            if ( $flag )
            {
                return redirect('admin/viewAboutUs');
            }
            else
            {
                return view('errors.500')->with('message', $help->getMessage());
            }
        }
        catch (\Exception $exception)
        {
            return $this->exceptionView($exception, __FUNCTION__);
        }
    }

    public function updateCustomerService(Request $request)
    {
        try
        {
            if ( ! $request->has('content') || ! isEmptyString($request->get('content')) )
            {
                return view('errors.500')->with('message', '参数错误');
            }

            $content = $request->get('content');
            $help = new Help();
            $flag = $help->updateCustomerService($content);

            if ( $flag )
            {
                return redirect('admin/viewCustomerService');
            }
            else
            {
                return view('errors.500')->with('message', $help->getMessage());
            }
        }
        catch (\Exception $exception)
        {
            return $this->exceptionView($exception, __FUNCTION__);
        }
    }

    public function updateHelp(Request $request)
    {
        try
        {
            if ( ! $request->has('content') || ! isEmptyString($request->get('content')) )
            {
                return view('errors.500')->with('message', '参数错误');
            }

            $content = $request->get('content');
            $help = new Help();
            $flag = $help->updateHelp($content);

            if ( $flag )
            {
                return redirect('admin/viewHelp');
            }
            else
            {
                return view('errors.500')->with('message', $help->getMessage());
            }
        }
        catch (\Exception $exception)
        {
            return $this->exceptionView($exception, __FUNCTION__);
        }
    }
}
